body {
  font-family: 'Arial', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  background: radial-gradient(circle at center, #FF7F50, #FFA07A);
  color: #fff;
  position: relative;
  /* Needed for positioning the help, tophat, and vault buttons */
  min-height: 100vh;
  /* Ensure body takes at least viewport height */
  padding-bottom: 20px;
  /* Add padding to make space below content */
  transition: background-color 0.3s ease, color 0.3s ease, background 0.3s ease, transform 0.5s ease; /* Added background and transform transition */
}

/* Dark Mode Styles */
body.dark-mode {
  background: radial-gradient(circle at center, #333, #1a1a1a);
  color: #eee;
}

/* Red Mode Styles (Light Mode) */
body.red-mode:not(.dark-mode) {
  background: radial-gradient(circle at center, #F44336, #D32F2F); /* Stronger reddish gradient */
}

/* Red Mode Styles (Dark Mode) */
body.dark-mode.red-mode {
    background: radial-gradient(circle at center, #8B0000, #440000); /* Darker reddish gradient for dark mode */
}

/* Rainbow Mode Styles */
body.rainbow-mode {
  animation: rainbowBackground 5s infinite alternate;
  background-size: 400% 400%; /* Needed for gradient animation */
}

@keyframes rainbowBackground {
  0% { background-position: 0% 50%; background: radial-gradient(circle at center, #FF0000, #FF7F00); }
  16% { background-position: 25% 50%; background: radial-gradient(circle at center, #FF7F00, #FFFF00); }
  33% { background-position: 50% 50%; background: radial-gradient(circle at center, #FFFF00, #00FF00); }
  50% { background-position: 75% 50%; background: radial-gradient(circle at center, #00FF00, #0000FF); }
  66% { background-position: 100% 50%; background: radial-gradient(circle at center, #0000FF, #4B0082); }
  83% { background-position: 75% 50%; background: radial-gradient(circle at center, #4B0082, #9400D3); }
  100% { background-position: 0% 50%; background: radial-gradient(circle at center, #9400D3, #FF0000); }
}

/* Upside Down Mode */
body.upside-down-mode {
    transform: rotate(180deg);
}

h1 {
  color: #fff;
  text-shadow: 2px 2px 4px #000000;
  margin-bottom: 20px;
}

body.dark-mode h1,
body.dark-mode #linktext {
  color: #eee;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

textarea {
  width: 80%;
  height: 150px;
  margin-bottom: 10px;
  padding: 10px;
  border: 2px solid #4CAF50;
  border-radius: 8px;
  font-size: 16px;
  background-color: #f8f8f8;
  color: #333;
  transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode textarea {
  background-color: #444;
  color: #eee;
  border-color: #666;
}

textarea:focus {
  border-color: #007bff;
  outline: none;
}

body.dark-mode textarea:focus {
   border-color: #0099ff;
}

button {
  padding: 12px 24px;
  font-size: 18px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.3);
  transition: background-color 0.3s ease, transform 0.3s ease;
}

body.dark-mode button {
  background-color: #007bff;
  box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.5);
}

button:hover {
  background-color: #367c39;
  transform: translateY(-2px);
}

body.dark-mode button:hover {
  background-color: #0056b3;
}

#help-button,
#dark-mode-toggle,
#vault-button,
#modifiers-button {
  position: absolute;
  top: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #4CAF50;
  color: white;
  font-size: 24px;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3);
  z-index: 10;
  transition: background-color 0.3s ease;
}

#help-button {
    right: 20px;
}

#dark-mode-toggle {
    right: 70px;
    font-size: 20px;
}

#vault-button {
    right: 120px;
    font-size: 20px;
}

#modifiers-button {
    right: 170px;
    font-size: 20px;
}


body.dark-mode #help-button,
body.dark-mode #dark-mode-toggle,
body.dark-mode #vault-button,
body.dark-mode #modifiers-button {
  background-color: #007bff;
  box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.5);
}

#help-button:hover,
#dark-mode-toggle:hover,
#vault-button:hover,
#modifiers-button:hover {
  background-color: #367c39;
}

body.dark-mode #help-button:hover,
body.dark-mode #dark-mode-toggle:hover,
body.dark-mode #vault-button:hover,
body.dark-mode #modifiers-button:hover {
  background-color: #0056b3;
}

#instructions-overlay,
#vault-overlay,
#modifiers-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
  display: none;
}

#instructions-box,
#vault-box,
#modifiers-box {
  background-color: #fff;
  padding: 20px;
  border-radius: 10px;
  max-width: 90%;
  max-height: 90%;
  overflow-y: auto;
  color: #333;
  position: relative;
  box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.5);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Counter-rotate the vault box when body is upside down */
body.upside-down-mode #vault-box {
    transform: rotate(-180deg);
}

body.dark-mode #instructions-box,
body.dark-mode #vault-box,
body.dark-mode #modifiers-box {
  background-color: #222;
  color: #eee;
  box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.7);
}

#instructions-box h2,
#vault-box h2,
#modifiers-box h2 {
  margin-top: 0;
  color: #4CAF50;
}

body.dark-mode #instructions-box h2,
body.dark-mode #vault-box h2,
body.dark-mode #modifiers-box h2 {
  color: #007bff;
}

#instructions-box p {
  margin-bottom: 15px;
  line-height: 1.5;
}

#instructions-box ul {
  margin-bottom: 15px;
  padding-left: 20px;
}

#instructions-box li {
  margin-bottom: 8px;
}

#instructions-box {
  max-height: 80%; /* Adjusted for scrollability */
  overflow-y: auto; /* Added scrollbar */
}

#close-instructions,
#close-vault,
#close-modifiers {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #aaa;
}

 body.dark-mode #close-instructions,
 body.dark-mode #close-vault,
 body.dark-mode #close-modifiers {
   color: #bbb;
}

#vault-code-input {
    width: calc(100% - 24px);
    padding: 10px;
    margin-bottom: 15px;
    border: 2px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
    box-sizing: border-box;
     background-color: #f8f8f8;
    color: #333;
    transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode #vault-code-input {
    background-color: #444;
    color: #eee;
    border-color: #666;
}

 #vault-submit {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    margin-bottom: 10px;
}

#vault-codes-section {
    margin-top: 20px;
    padding-top: 10px;
    border-top: 1px solid #ccc;
    transition: max-height 0.3s ease-out, border-color 0.3s ease;
    overflow: hidden; /* Hide overflowing content when collapsed */
}

body.dark-mode #vault-codes-section {
    border-color: #666;
}

#vault-codes-section.collapsed {
    max-height: 30px; /* Small height when collapsed, enough for the title */
}

#vault-codes-section:not(.collapsed) {
    max-height: 500px; /* Adjust as needed for expanded height */
}

#toggle-vault-codes {
    cursor: pointer;
    font-size: 1.1em;
    color: #4CAF50;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between; /* To push arrow to the right */
    transition: color 0.3s ease;
}

body.dark-mode #toggle-vault-codes {
    color: #007bff;
}

#vault-codes-list {
    margin-top: 10px;
    max-height: 300px; /* Allow scrolling for codes list */
    overflow-y: auto;
    padding-right: 10px; /* Space for scrollbar */
}

#vault-codes-list p {
    margin-bottom: 5px;
    font-size: 0.9em;
    line-height: 1.3;
    color: #333;
    transition: color 0.3s ease;
}

body.dark-mode #vault-codes-list p {
    color: #eee;
}

#vault-codes-list strong {
    color: #4CAF50;
    transition: color 0.3s ease;
}

body.dark-mode #vault-codes-list strong {
    color: #007bff;
}

#modifier-search-bar {
  width: calc(100% - 24px);
  padding: 10px;
  margin-bottom: 15px;
  border: 2px solid #ccc;
  border-radius: 4px;
  font-size: 16px;
  box-sizing: border-box;
  background-color: #f8f8f8;
  color: #333;
  transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode #modifier-search-bar {
  background-color: #444;
  color: #eee;
  border-color: #666;
}

#modifiers-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 15px;
  /* Add scrolling */
  max-height: 60vh; /* Set a maximum height */
  overflow-y: auto; /* Add vertical scroll if content exceeds height */
  padding-right: 15px; /* Add padding for the scrollbar */
}

.modifier-section-header {
  margin-top: 20px;
  margin-bottom: 10px;
  font-size: 1.2em;
  color: #4CAF50; /* Adjust color as needed */
  border-bottom: 1px solid #ccc;
  padding-bottom: 5px;
  transition: color 0.3s ease, border-color 0.3s ease;
}

body.dark-mode .modifier-section-header {
  color: #007bff;
  border-color: #666;
}

.modifier-section-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modifier-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap; /* Allow description to wrap */
}

.modifier-item label {
  margin-left: 8px;
  font-weight: bold;
  margin-right: 8px; /* Add some space between label and description */
}

.modifier-description {
    font-size: 0.9em;
    color: #666;
    font-style: italic;
    margin-left: 28px; /* Align with checkbox+label indent */
    flex-basis: 100%; /* Force description to new line on smaller screens */
    transition: color 0.3s ease;
}

body.dark-mode .modifier-description {
    color: #bbb;
}

#output {
  width: 80%;
  margin-top: 30px;
  padding: 25px;
  border: 2px solid #4CAF50;
  border-radius: 8px;
  background-color: #fff;
  white-space: pre-wrap;
  box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.3);
  font-family: 'Arial', sans-serif;
  color: #333;
  transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
  line-height: 1.2; /* Adjust this value as needed to reduce spacing */
  text-indent: 0; /* Remove indentation */
}

body.dark-mode #output {
  background-color: #444;
  color: #eee;
  border-color: #666;
  box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.5);
}

.character-section {
  width: 80%;
  margin-top: 20px; /* Adjusted margin top */
  padding: 25px;
  border: 2px solid #4CAF50;
  border-radius: 8px;
  background-color: #fff;
  box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.3);
  color: #333;
  transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode .character-section {
  background-color: #222;
  color: #eee;
  border-color: #666;
  box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.5);
}

.character-section h2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.character-section h2:after {
  content: '−'; /* Changed to unicode minus sign */
  font-size: 20px;
  margin-left: 10px;
}

.character-section.collapsed h2:after {
  content: '+'; /* Changed to unicode plus sign */
}

.character-section.collapsed .character-list,
.character-section.collapsed .search-bar,
.character-section.collapsed .placeholder-text {
  display: none;
}

.character-section.collapsed .custom-character-input {
  display: none;
}

.character-section .search-bar {
    width: calc(100% - 20px);
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
    background-color: #f8f8f8;
    color: #333;
     transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode .character-section .search-bar {
    background-color: #444;
    color: #eee;
    border-color: #555;
}

.character-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.character-row label {
  margin-left: 8px;
  font-weight: bold;
}

.character-description {
  font-style: italic;
  color: #666;
  margin-left: 30px;
  transition: color 0.3s ease;
}

body.dark-mode .character-description {
  color: #bbb;
}

.placeholder-text {
  text-align: center;
  font-size: 1.1em;
  color: #888;
  margin-top: 15px;
  transition: color 0.3s ease;
}

body.dark-mode .placeholder-text {
  color: #999;
}

#linktext {
  color: white;
  font-weight: bold;
  text-shadow: 2px 2px 4px #000000;
  margin-bottom: 15px;
  padding: 10px;
  border: 2px solid #4CAF50;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.2);
  transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode #linktext {
    border-color: #666;
    background-color: rgba(0, 0, 0, 0.2);
     box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.4);
}

input[type="checkbox"] {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid #4CAF50;
  border-radius: 4px;
  background-color: #fff;
  cursor: pointer;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

body.dark-mode input[type="checkbox"] {
  border-color: #007bff;
  background-color: #333;
}

input[type="checkbox"]:checked {
  background-color: #4CAF50;
  border-color: #4CAF50;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
  background-size: 70%;
  background-position: center;
  background-repeat: no-repeat;
}

body.dark-mode input[type="checkbox"]:checked {
  background-color: #007bff;
  border-color: #007bff;
   background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
}

#length-controls {
  display: flex;
  align-items: center;
  margin-bottom: 5px; /* Reduced margin to bring the counter closer */
  color: white;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000000;
  transition: color 0.3s ease, text-shadow 0.3s ease;
}

body.dark-mode #length-controls {
  color: #eee;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

#word-count-display {
  margin-top: 5px; /* Added margin to position it below the slider */
  margin-bottom: 20px; /* Space between counter and next button */
  color: white;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000000;
  transition: color 0.3s ease, text-shadow 0.3s ease;
}

body.dark-mode #word-count-display {
  color: #eee;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}


#length-slider {
  width: 150px;
  margin: 0 10px;
  appearance: none;
  height: 8px;
  background: #ddd;
  outline: none;
  opacity: 0.7;
  transition: opacity .2s, background 0.3s ease;
  border-radius: 5px;
}

body.dark-mode #length-slider {
  background: #555;
}

#length-slider::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #4CAF50;
  cursor: pointer;
  transition: background 0.3s ease;
}

body.dark-mode #length-slider::-webkit-slider-thumb {
  background: #007bff;
}

#length-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #4CAF50;
  cursor: pointer;
   transition: background 0.3s ease;
}

body.dark-mode #length-slider::-moz-range-thumb {
   background: #007bff;
}

/* Style for the new Select All Characters button */
#select-all-characters {
    margin-top: 15px; /* Adjusted margin top to place it below generate button */
    margin-bottom: 20px; /* Keep some space below the button */
}

/* Custom Character Section Styles */
.custom-character-input {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 15px;
  margin-bottom: 15px; /* Space between input and list */
}

#custom-character-name,
#custom-character-description {
  width: calc(100% - 20px); /* Account for padding */
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
  background-color: #f8f8f8;
  color: #333;
  transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode #custom-character-name,
body.dark-mode #custom-character-description {
  background-color: #444;
  color: #eee;
  border-color: #555;
}

#custom-character-description {
  height: 80px; /* Make textarea taller */
  resize: vertical; /* Allow vertical resizing */
}

#add-custom-character,
#remove-selected-custom-characters {
  padding: 10px 15px;
  font-size: 16px;
  margin-top: 0; /* Override default button margin */
  width: auto; /* Allow buttons to size based on content */
  align-self: flex-start; /* Align to the left within the flex container */
}

#remove-selected-custom-characters {
  background-color: #dc3545; /* Red color for remove button */
}

#remove-selected-custom-characters:hover {
  background-color: #c82333;
}

body.dark-mode #remove-selected-custom-characters {
  background-color: #bd2130;
}

body.dark-mode #remove-selected-custom-characters:hover {
  background-color: #a71d2a;
}